<%@ page import="com.interfaces.*" %>
<%@ page import="com.core.visaInfo.pojo.VisaInfo" %>
<%@ page import="com.core.visaInfo.VisaInfoJspKeys" %>
<%@ page import="com.core.sysDict.SysDictJsp" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<!--
This is a starter template page. Use this page to start your new project from
scratch. This page gets rid of all links and provides the needed markup only.
-->
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>签证信息管理</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">

    <%
        String path = request.getContextPath();
        path = "/".equals(path)?"":path;
        request.setAttribute("path", path);
        String sysDictJson=SysDictJsp.getSysDictJson(session);
    %>
    <script type="text/javascript">
        var path = "${path}";
    </script>

    <!-- Bootstrap 3.3.6 -->
     <link rel="stylesheet" href="${path}/public/adminlte/bootstrap/css/bootstrap.min.css"> 
    <!-- bootstrap datepicker -->
  	<link rel="stylesheet" href="${path}/public/adminlte/plugins/datepicker/datepicker3.css">
    <!-- Font Awesome -->
     <link rel="stylesheet" href="${path}/public/font-awesome-4.7.0/css/font-awesome.min.css">
    <!--datatable-editor  -->
     <link rel="stylesheet" href="${path}/js/datatable-editor/1.6.1/css/editor.dataTables.min.css">
    <!-- Ionicons -->
     <link rel="stylesheet" href="${path}/public/ionicons/ionicons.min.css"> 
    <!-- DataTables -->
      <link rel="stylesheet" href="${path}/public/adminlte/plugins/datatables/dataTables.bootstrap.css"> 
    <!-- Select2 -->
  	<link rel="stylesheet" href="${path}/public/adminlte/plugins/select2/select2.min.css"> 
    <!-- Theme style -->
     <link rel="stylesheet" href="${path}/public/adminlte/dist/css/AdminLTE.min.css"> 
    <!-- AdminLTE Skins. We have chosen the skin-blue for this starter
          page. However, you can choose any other skin. Make sure you
          apply the skin class to the body tag so the changes take effect.
    --><!-- 
    --> <link rel="stylesheet" href="${path}/public/adminlte/dist/css/skins/_all-skins.min.css">

     <link rel="stylesheet" href="${path}/css/common.css">
     <link rel="stylesheet" href="${path}/js/datatable-editor/1.6.1/css/select.dataTables.min.css">
 	<!-- bootstrap datepicker -->
  	<link rel="stylesheet" href="${path}/public/adminlte/plugins/datepicker/datepicker3.css">
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <script type="text/javascript" src="${path}/js/json2.js"></script>
</head>
<body >
<%
	VisaInfo visaInfo = (VisaInfo) request.getAttribute(VisaInfoJspKeys.JspParam_VisaInfo);
 %>

<div class="container">
	 <button type="submit" class="btn btn-primary" id="btnUpdate1">保 存</button>
	 <button class="btn btn-primary" onclick="btnUpdateState(1)">提 交</button>
	 <button class="btn btn-primary" onclick="btnUpdateState(4)">退回修改</button>
	 <button class="btn btn-primary" onclick="btnUpdateState(0)">取消提交</button>
	 <button class="btn btn-primary" onclick="btnUpdateState(2)">撤 销</button>
	 <button class="btn btn-primary" onclick="btnUpdateDel()">删 除</button>
	 <div class="box box-primary">
	 	<h3 class="box-title">签证基本信息</h3>
	 	<div class="row">
	 			 <div class="col-md-4">
                    <div class="form-group">
                        <label for="state">当前签证状态</label>
                        <select readonly="readonly"  class="form-control" id="state" value="${visaInfo.state}"></select>
                    </div>
                </div>
                 <div class="col-md-4">
                    <div class="form-group">
                        <label for="incomingDate">入境日期</label>
                        <input type="text" class="form-control" id="incomingDate"value="${visaInfo.incomingDate}">
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="form-group">
                        <label for="leaveDate">出境日期</label>
                        <input type="text"  class="form-control" id="leaveDate"value="${visaInfo.leaveDate}">
                    </div>
                </div>
        </div>
        <div class="row">
                <div class="col-md-4">
                    <div class="form-group">
                        <label for="visaType">签证类型</label>
                        <select  class="form-control" id="visaType" value="${visaInfo.visaType}">
                        </select>
                    </div>
                </div>
                 <div class="col-md-4">
                    <div class="form-group">
                        <label for="sendAgentId">送签社</label>
                        <select  class="form-control select2" id="sendAgentId">
                        </select>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="form-group">
                        <label for="entryFlight">入境航班</label>
                        <input type="text"  class="form-control" id="entryFlight" value="${visaInfo.entryFlight}">
                    </div>
                </div>
        </div>
            <div class="row">
            	
                <div class="col-md-4">
                    <div class="form-group">
                        <label for="entryPoint">入境口岸</label>
                        <input type="text"   class="form-control" id="entryPoint" value="${visaInfo.entryPoint}">
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="form-group">
                        <label for="exitPoint">出境口岸</label>
                        <input type="text"  class="form-control" id="exitPoint" value="${visaInfo.exitPoint}">
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="form-group">
                        <label for="exitFlight">出境航班</label>
                        <input type="text"   class="form-control" id="exitFlight" value="${visaInfo.exitFlight}">
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-md-4">
                    <div class="form-group"id="isStateNorthCountry1">
                        <label for="isStateNorthCountry">要在冲绳和东北六省哪里住</label>
                        <select   class="form-control" id="isStateNorthCountry" value="${visaInfo.isStateNorthCountry}">
                        </select>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="form-group" id="isPastCome1">
                        <label for="isPastCome">过去是否来过</label>
                        <select class="form-control" id="isPastCome" value="${visaInfo.isPastCome}">
                        	<option value="#">==请选择==</option>
                       		<option value="0"<%if("0".equals(visaInfo.getIsPastCome())){%>selected = "selected"<%}%>>否</option>
                       		<option value="1"<%if("1".equals(visaInfo.getIsPastCome())){%>selected = "selected"<%}%>>是</option>
                        </select>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="form-group" id="pastCameRecord1">
                        <label for="pastCameRecord" id="pastCameRecord1">过去访问过城市的记录</label>
                        <select   class="form-control" id="pastCameRecord" value="${visaInfo.pastCameRecord}">
                        </select>
                    </div>
                </div>
            </div>
            <div class="row">
            	
            	<div class="col-md-4">
                    <div class="form-group" id="txtVisaInfoId1">
                        <label for="txtVisaInfoId">签证代码</label>
                        <input type="text" class="form-control" id="txtVisaInfoId" readonly="readonly" value="${visaInfo.id}">
                    </div>
                </div>
            </div>
	 </div>
     <div class="box box-primary">
     	 <h3 class="box-title">人员基本信息</h3>
         <div class="box-body">
            <table id="dg1" class="table table-bordered table-hover">
            </table>
         </div>
         <!-- /.box-body -->
     </div>   
     <div class="box box-primary">
     	 <h3 class="box-title">行程</h3>
         <div class="box-body">
            <table id="dg2" class="table table-bordered table-hover">
            </table>
         </div>
         <!-- /.box-body -->
     </div>         
<!-- ./wrapper -->
</div>
<!-- REQUIRED JS SCRIPTS -->

<!-- jQuery 2.2.3 -->
<script src="${path}/public/adminlte/plugins/jQuery/jquery-2.2.3.min.js"></script>
<!-- Bootstrap 3.3.6 -->
<script src="${path}/public/adminlte/bootstrap/js/bootstrap.min.js"></script>
<!-- DataTables -->
<script src="${path}/js/datatable-editor/1.6.1/js/jquery.dataTables.min.js"></script>
<script src="${path}/public/adminlte/plugins/datatables/dataTables.bootstrap.min.js"></script>
<!-- bootstrap datepicker -->
<script src="${path}/public/adminlte/plugins/datepicker/bootstrap-datepicker.js"></script>
<!-- Select2 -->
<script src="${path}/public/adminlte/plugins/select2/select2.full.min.js"></script>
<!--inLine  -->
<script src="${path}/public/inLine/dataTables.buttons.min.js"></script>
<script src="${path}/js/datatable-editor/1.6.1/js/dataTables.editor.min.js"></script>
<script src="${path}/public/inLine/dataTables.select.min.js"></script>
<!-- SlimScroll -->
<script src="${path}/public/adminlte/plugins/slimScroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="${path}/public/adminlte/plugins/fastclick/fastclick.js"></script>
<!-- AdminLTE App -->
<script src="${path}/public/adminlte/dist/js/app.min.js"></script>
<script src="${path}/js/sysDict.js"></script>
<script src="${path}/js/PYtranslate.js"></script>
<!-- bootstrap datepicker -->
<script src="${path}/public/adminlte/plugins/datepicker/bootstrap-datepicker.js"></script>
<!-- Optionally, you can add Slimscroll and FastClick plugins.
     Both of these plugins are recommended to enhance the
     user experience. Slimscroll is required when using the
     fixed layout. -->
<!-- page script -->
<script>
var table;
var table2;
$("#state").attr("disabled","disabled");
$(document).ready(function() {
	function selectOption(key_no,key_value,re,flag){
	var tempoption=new Array();
	if(flag==0){
		tempoption.push({label:'==请选择==',value:"#"})
	}else if(flag==1){
		//此处选择无赋值，是因为后台会判定该值是否为null或空，若是，不作为查询条件添加到查询sql中
		tempoption.push({label:'全部',value:""})
	}
	$.each(re.data,function(i,n){
		if(n.key_no==key_no){
			if(n.key_value!='#'){
				tempoption.push({label:n.key_caption,value:n.key_value})
			}
		}
	});
	return tempoption;
}
	var sysDict1='<%=sysDictJson%>';
	var re1 = JSON.parse(sysDict1);
	var temPlaceOfPass=selectOption('1003',null,re1,0);
	var visaInfoId1=$("#txtVisaInfoId").val();
	console.info(visaInfoId1);
    editorForCreate = new $.fn.dataTable.Editor( {
    	idSrc:  'id',
    	i18n : {  
        create : {  
            title : "新增人员信息",  
            submit : "添加"  
        }  
    },  
	ajax: function ( method, url, data, success, error ) {  
                    var result={};  
                    for(var i in data.data){  
                        var result=data.data[i];  
                        result.DT_RowId=i;  
                        result.action=data.action;  
                        console.log(result);  
                    }  
                    $.ajax( {  
                        type: "post",  
                        "url":"${path}<%=VisitorController.URL_ADD_UPDATE%>",
                        data: result,  
                        dataType: "json",  
                        success: function (json) {
                        console.log(json);
                        if(json.returnCode=="0"){
                        	success(json);
                        	table.ajax.reload();
                        	var url= window.location.search;
                			var arr = url.split('&');
                        	parent.refresh(arr[arr.length-1]);   
                        }else{
                        success(json);
                        alert("不成功!");
                        }  
                        }  
                    } );  
                },   
        table: "#dg1",
        fields: [ {
                label: "姓名:",
                attr: {
  				"class": 'nameCreate'},
                name: "name"
            }, {
                label: "姓名拼音:",
                attr: {"class": 'PYnameCreate'},
                name: "pinyinName"
            },{
                label: "性别:",
                type:"radio",
                options: [
                    { label: "男", value:"1" },
                    { label: "女",  value:"2" }
                ],
                name: "sex",
                def:"0"
            }, {
                label: "护照:",
                name: "passport"
            }, {
                label: "居住地:",
                name: "permanentCity"
            }, {
                label: "出生日期:",
                name: "birthday",
                type: "datetime"
            }, {
                label: "职位:",
                name: "positions"
                
            }, {
                label: "是否是主申请人:",
                name: "isLead",
                type:"radio",
                options:[
                    { label: "否", value: 0 },
                    { label: "是",  value: 1 }
                ],
                def:0
                
            },
            {
                label: "护照发行地:",
                name: "placeOfIssue",
                type:"select",
                options:temPlaceOfPass,
            },
            {
                label: "出国记录:",
                type:"select",
                name: "exitRecords",
                options:[
                    { label: "无", value: 0 },
                    { label: "良好", value: 1 }
                ],
                def: 0
            },
            {
                label: "婚姻情况:",
                name: "marriage",
                type:"select",
                options:[
                    { label: "未婚", value: 0 },
                    { label: "已婚", value: 1 },
                    { label: "离婚", value: 2 },
                    { label: "丧偶", value: 3 }
                ],
                def: 0
            },
            {
                label: "身份确认:",
                name: "identificationWay",
                type:"select",
                options:[
                    { label: "身份证", value: 0 }
                ],
                def: 0
            },
            {
                label: "经济能力确认:",
                name: "economyProve",
            },
            {
                label: "金额:",
                name: "money",
            },
            {
                label: "联系方式:",
                name: "phone",
            },
            {
                label: "签证id:",
                name: "visaInfoId",
                def: visaInfoId1
            },
            {
                label: "旅行社意见:",
                name: "evaluation",
                def: "推荐"
            },
        ],
    });
    $(".nameCreate").change(function(){
  		console.info(".nameCreate");
	});
editorForEdit = new $.fn.dataTable.Editor({  
        idSrc:'id',
        i18n : {  
            edit : {  
                title : "修改人员信息",  
                submit : "修改"  
            }  
        },  
        ajax: function ( method, url, data, success, error ) {  
                    var result={};  
                    for(var i in data.data){  
                        var result=data.data[i];  
                        result.DT_RowId=i;  
                        result.action=data.action;  
                        console.log(result);  
                    }  
                    $.ajax( {  
                        type: "post",  
                        "url":"${path}<%=VisitorController.URL_UPDATE%>",
                        data: result,  
                        dataType: "json",  
                        success: function (json) {
                        console.log(json);
                        if(json.returnCode=="0"){
                        	success(json);
                        	table.ajax.reload();
                        	var url= window.location.search;
                			var arr = url.split('&');
                        	parent.refresh(arr[arr.length-1]);  
                        }else{
                        success(json);
                        alert("不成功!");
                        }  
                        }  
                    } );  
                },    
        table: "#dg1",
        fields: [ {
                label: "姓名:",
                name: "name"
            }, {
                label: "姓名拼音:",
                name: "pinyinName"
            }, {
                label: "性别:",
                type:"select",
                options: [
                    { label: "男", value:"1" },
                    { label: "女",  value:"2" }
                ],
                name: "sex"
               
            }, {
                label: "护照:",
                name: "passport"
            }, {
                label: "居住地:",
                name: "permanentCity"
            }, {
                label: "出生日期:",
                name: "birthday",
                type: "datetime"
            }, {
                label: "职位:",
                name: "positions"
                
            }, {
                label: "签证id:",
                name: "visaInfoId",
            },
            {
                label: "id:",
                name: "id",
            },
            {
                label: "是否是主申请人:",
                name: "isLead",
                type:"select",
                options:[
                    { label: "否", value:"0" },
                    { label: "是",  value:"1" }
                ],
            },
            {
                label: "护照发行地:",
                type:"select",
                name: "placeOfIssue",
                options:temPlaceOfPass,
            },
            {
                label: "出国记录:",
                type:"select",
                name: "exitRecords",
                options:[
                    { label: "无", value: 0 },
                    { label: "良好", value: 1 }
                ],
                def: 0
            },
            {
                label: "婚姻情况:",
                name: "marriage",
                type:"select",
                options:[
                    { label: "未婚", value: 0 },
                    { label: "已婚", value: 1 },
                    { label: "离婚", value: 2 },
                    { label: "丧偶", value: 3 }
                ],
            },
            {
                label: "身份确认:",
                name: "identificationWay",
                type:"select",
                options:[
                    { label: "身份证", value: 0 }
                ],
                def: 0
            },
            {
                label: "经济能力确认:",
                name: "economyProve",
            },
            {
                label: "金额:",
                name: "money",
            },
            {
                label: "联系方式:",
                name: "phone",
            },
            {
                label: "旅行社意见:",
                name: "evaluation",
            },
        ],
    });
    editorForDel = new $.fn.dataTable.Editor({  
        idSrc:'id',
        i18n : {  
            remove: {
                button: "删除",
                title:  "删除",
                submit: "确定",
                confirm: {
                    _: "确定要删除这 %d 条记录?",
                    1: "确定要删除这 1 条记录?"
                }
            }  
        },  
        ajax: function ( method, url, data, success, error ) {  
                    var result={};  
                    for(var i in data.data){  
                        var result=data.data[i];  
                        result.DT_RowId=i;  
                        result.action=data.action;  
                        console.log(result);  
                    }  
                    $.ajax( {  
                        type: "post",  
                        "url":"${path}<%=VisitorController.URL_DEL%>",
                        data: result,  
                        dataType: "json",  
                        success: function (json) {
                        console.log(json);
                        if(json.returnCode=="0"){
                        	success(json);
                        	table.ajax.reload();  
                        }else{
                        success(json);
                        alert("不成功!");
                        }  
                        }  
                    } );  
                },    
        table: "#dg1",
        fields: [ {
                label: "姓名:",
                name: "name"
            }, {
                label: "姓名拼音:",
                name: "pinyinName"
            }, {
                label: "性别:",
                type:"select",
                options: [
                    { label: "男", value:"1" },
                    { label: "女",  value:"2" }
                ],
                name: "sex"
               
            }, {
                label: "护照:",
                name: "passport"
            }, {
                label: "居住地:",
                name: "permanentCity"
            }, {
                label: "出生日期:",
                name: "birthday",
                type: "datetime"
            }, {
                label: "职位:",
                name: "positions"
                
            }, {
                label: "签证id:",
                name: "visaInfoId",
            },
            {
                label: "id:",
                name: "id",
            },
            {
                label: "是否是负责人:",
                name: "isLead",
                type:"select",
                options:[
                    { label: "否", value: 0 },
                    { label: "是",  value: 1 }
                ],
                def:1
            }
        ],
    });
    table =$('#dg1').DataTable( {
    	select: true,
    	searching : false,
    	serverSide:true,
    	"iDisplayLength" : 10,
    	"lengthChange": true,
    	paginate : true,  
    	"processing" : true,
        dom: "Bfrtip",
        "ajax":{
            	 "url":"${path}<%=VisitorController.URL_DB_SEARCH%>?visaInfoId="+visaInfoId1,
            	 "type":"post",
            	 "dataType":"JSON",
            },
        columns: [
            {
                data: null,
                defaultContent: '',
                className:'select-checkbox',
            },
            { data: "id","title":"id","visible": false, },
            { data: "name","title":"姓名" },
            { data: "pinyinName","title":"拼音" },
            { 
            data: "sex",
            "title":"性别",
            "render": function (val, type, row) {
                    return val == 1 ? "男" : "女";
                }
            },
            { data: "permanentCity","title":"居住地",defaultContent:"" },
            { data: "birthday","title":"出生日期",defaultContent:"" },
            { data: "passport","title":"护照",defaultContent:""},
            { data: "positions","title":"职位",defaultContent:""},
            { 
            data: "isLead",
            "title":"是否是主申请人",
            "render": function (val, type, row) {
                    return val == 0 ? "否" : "是";
                }
            }
        ],
        order: [ 1, 'asc' ],
        select: {
            style:'os',
            selector: 'td:first-child',
        },
        buttons: [
            { extend: "create", editor: editorForCreate,text:'新增'},
            { extend: "edit", editor: editorForEdit,text:'编辑'},
            { extend: "remove", editor: editorForDel,text:'删除' }
        ],
        language: {
            processing:     "Traitement en cours...",
            search:         "Rechercher&nbsp;:",
            lengthMenu:     " ",
            info:           " ",
            infoEmpty:      " ",
            infoFiltered:   " ",
            infoPostFix:    "",
            loadingRecords: "查询中...",
            zeroRecords:    "没有找到数据",
            emptyTable:     "暂时没有数据",
            "paginate": {
        		"first":      "首页",
        		"last":       "尾页",
        		"next":       "下一页",
        		"previous":   "上一页"
    		},
            }
    } );
    /* 第二个表格 行程信息 */
    editorForCreate2 = new $.fn.dataTable.Editor( {
    	idSrc:  'id',
    	i18n : {  
        create : {  
            title : "新增行程信息",  
            submit : "添加"  
        }  
    },  
	ajax: function ( method, url, data, success, error ) {  
                    var result={};  
                    for(var i in data.data){  
                        var result=data.data[i];  
                        result.DT_RowId=i;  
                        result.action=data.action;  
                        console.log(result);  
                    }  
                    $.ajax( {  
                        type: "post",  
                        "url":"${path}<%=JourneyController.URL_ADD_UPDATE%>",
                        data: result,  
                        dataType: "json",  
                        success: function (json) {
                        console.log(json);
                        if(json.returnCode=="0"){
                        	success(json);
                        	table2.ajax.reload();  
                        }else{
                        success(json);
                        alert("不成功!");
                        }  
                        }  
                    } );  
                },   
        table: "#dg2",
        fields: [ {
                label: "活动:",
                name: "activity"
            }, {
            	label: "行动日期:",
                name: "actionDate",
                type: "datetime"
                
            }, {
                label: "住宿处:",
                name: "hotel"
            }, 
            {
                label: "景点:",
                name: "view"
            }, 
            {
                label: "签证id:",
                name: "visaInfoId",
                def: visaInfoId1
            }
            
        ],
    });
    
    editorForEdit2 = new $.fn.dataTable.Editor({  
        idSrc:'id',
        i18n : {  
            edit : {  
                title : "修改行程信息",  
                submit : "修改"  
            }  
        },  
        ajax: function ( method, url, data, success, error ) {  
                    var result={};  
                    for(var i in data.data){  
                        var result=data.data[i];  
                        result.DT_RowId=i;  
                        result.action=data.action;  
                        console.log(result);  
                    }  
                    $.ajax( {  
                        type: "POST",  
                        "url":"${path}<%=JourneyController.URL_UPDATE%>",
                        data: result,  
                        dataType: "json",  
                        success: function (json) {
                        console.log(json);
                        if(json.returnCode=="0"){
                        	success(json);
                        	table2.ajax.reload();    
                        }else{
                        success(json);
                        alert("不成功!");
                        }  
                        }  
                    } );  
                },    
        table: "#dg2",
        fields: [ {
        		label: "活动:",
                name: "activity"
                
            }, {
                label: "行动日期:",
                name: "actionDate",
                type:"datetime"
            }, {
                label: "住宿处:",
                name: "hotel"
            },{
                label: "景点:",
                name: "view"
            },{
                label: "签证代码",
                name: "visaInfoId",
                def: visaInfoId1
            },
            {
                label: "id:",
                name: "id",
            }
        ],
    });
    editorForDel2 = new $.fn.dataTable.Editor({  
        idSrc:'id',
        i18n : {  
            remove: {
                button: "删除",
                title:  "删除",
                submit: "确定",
                confirm: {
                    _: "确定要删除这 %d 条记录?",
                    1: "确定要删除这 1 条记录??"
                }
            }
        },  
        ajax: function ( method, url, data, success, error ) {  
                    var result={};  
                    for(var i in data.data){  
                        var result=data.data[i];  
                        result.DT_RowId=i;  
                        result.action=data.action;  
                        console.log(result);  
                    }  
                    $.ajax( {  
                        type: "POST",  
                        "url":"${path}<%=JourneyController.URL_DEL%>",
                        data: result,  
                        dataType: "json",  
                        success: function (json) {
                        console.log(json);
                        if(json.returnCode=="0"){
                        	success(json);
                        	
                        	table2.ajax.reload();  
                        }else{
                        success(json);
                        alert("不成功!");
                        }  
                        }  
                    } );  
                },    
        table: "#dg2",
        fields: [ {
        		label: "活动:",
                name: "activity"
                
            }, {
                label: "行动日期:",
                name: "actionDate",
                type:"datetime"
            }, {
                label: "住宿处:",
                name: "hotel"
            },{
                label: "景点:",
                name: "view"
            },{
                label: "签证id:",
                name: "visaInfoId",
                def: visaInfoId1
            },
            {
                label: "id:",
                name: "id",
            }
        ],
    });
    table2 =$('#dg2').DataTable( {
    	select: true,
    	searching : false,
    	paginate : false, 
        dom: "Bfrtip",
        "ajax":{
            	 "url":"${path}<%=JourneyController.URL_DB_SEARCH%>?visaInfoId="+visaInfoId1,
            	 "type":"post",
            	 "dataType":"JSON",
            },
        columns: [
            {
                data: null,
                defaultContent: '',
                className:"select-checkbox",
                
            },
            { data: "id","title":"id","visible": false },
            { data: "actionDate","title":"行动日期" },
            { data: "activity","title":"活动" },
            { data: "hotel","title":"住宿处" },
            { data: "view","title":"景点" },
            
        ],
        order: [ 1, 'asc' ],
        select: {
            style:'os',
            selector: 'td:first-child',
        },
        buttons: [
            { extend: "create", editor: editorForCreate2,text:'新增'},
            { extend: "edit", editor: editorForEdit2,text:'编辑'},
            { extend: "remove", editor: editorForDel2,text:'删除' },
        ],
        language: {
            processing:     "Traitement en cours...",
            search:         "Rechercher&nbsp;:",
            lengthMenu:     " ",
            info:           " ",
            infoEmpty:      " ",
            infoFiltered:   " ",
            infoPostFix:    "",
            loadingRecords: "查询中...",
            zeroRecords:    "没有找到数据",
            emptyTable:     "暂时没有数据",
            
            }
    } );
    table.select();
    table2.select();
     table.buttons().container().appendTo("#buttons");
     table2.buttons().container().appendTo("#buttons");
     
     /* 内联编辑 */      
    /* $('#dg1').on( 'click', 'tbody td:not(:first-child)', function (e) {
        editorForEdit.inLine( this, { submit: 'allIfChanged' });
    } );
     $('#dg2').on( 'click', 'tbody td:not(:first-child)', function (e) {
        editorForEdit2.inLine( this, { submit: 'allIfChanged' });
    } ); */
    /* 隐藏行数 */
   editorForCreate.hide('visaInfoId');
   editorForEdit.hide('visaInfoId');
   editorForEdit2.hide('visaInfoId');
   editorForEdit.hide('id');
   editorForEdit2.hide('id');
   editorForCreate2.hide('visaInfoId');
   
   /* 第一个表单验证 */
   editorForCreate.on( 'preSubmit', function ( e, o, action ) {
        if ( action !== 'remove' ) {
            var name = this.field( 'name');
 			var pinyinName=this.field('pinyinName');
 			var sex = this.field('sex');
 			var permanentCity=this.field( 'permanentCity');
 			var birthday=this.field( 'birthday');
 			var passport=this.field( 'passport');
 			var isLead=this.field( 'isLead');
            // Only validate user input values - different values indicate that
            // the end user has not entered a value
            if ( ! name.isMultiValue() ) {
                if ( ! name.val() ) {
                    name.error( '名字不能为空!' );
                }
                if ( name.val().length >= 20 ) {
                    name.error( '名字不能超过20个字符!' );
                }
            }//名字检测
            if ( ! pinyinName.isMultiValue() ) {
                if ( ! pinyinName.val() ) {
                    pinyinName.error( '名字不能为空!' );
                }
                if ( pinyinName.val().length >= 40 ) {
                    name.error( '名字拼音不能超过40个字符!' );
                }
            }//拼音检测
            console.info(sex.val());
            if ( ! permanentCity.isMultiValue() ) {
                if ( ! permanentCity.val() ) {
                    permanentCity.error( '居住地不能为空!' );
                }
                if ( permanentCity.val().length>6 ) {
                    permanentCity.error( '居住地地址过长!' );
                }
            }//居住地检测
            if ( ! birthday.isMultiValue() ) {
                if ( ! birthday.val() ) {
                    birthday.error( '出生日期不能为空!' );
                }else{
                	var r = birthday.val().match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/); 
					if(r==null){
					birthday.error( '出生日期格式错误!' );
					} 
                }
            }//出生日期检测地检测
            if ( ! passport.isMultiValue() ) {
                if ( ! passport.val() ) {
                    passport.error( '护照不能为空!' );
                }
                if ( passport.val().length>=30 ) {
                    passport.error( '护照不是符合的格式!' );
                }
            }//护照检测
            if ( this.inError() ) {
                return false;
            }
        }
    } );
    
       /* 第一个表单验证2 */
   editorForEdit.on( 'preSubmit', function ( e, o, action ) {
        if ( action !== 'remove' ) {
            var name = this.field( 'name');
 			var pinyinName=this.field('pinyinName');
 			var sex = this.field('sex');
 			var permanentCity=this.field( 'permanentCity');
 			var birthday=this.field( 'birthday');
 			var passport=this.field( 'passport');
 			var isLead=this.field( 'isLead');
            if ( ! name.isMultiValue() ) {
                if ( ! name.val() ) {
                    name.error( '名字不能为空!' );
                }
                if ( name.val().length >= 20 ) {
                    name.error( '名字不能超过20个字符!' );
                }
            }//名字检测
            if ( ! pinyinName.isMultiValue() ) {
                if ( ! pinyinName.val() ) {
                    pinyinName.error( '名字不能为空!' );
                }
                if ( pinyinName.val().length >= 40 ) {
                    name.error( '名字拼音不能超过40个字符!' );
                }
            }//拼音检测
            console.info(sex.val());
            if ( ! permanentCity.isMultiValue() ) {
                if ( ! permanentCity.val() ) {
                    permanentCity.error( '居住地不能为空!' );
                }
                if ( permanentCity.val().length>=30 ) {
                    permanentCity.error( '居住地地址过长!' );
                }
            }//居住地检测
            if ( ! birthday.isMultiValue() ) {
                if ( ! birthday.val() ) {
                    birthday.error( '出生日期不能为空!' );
                }else{
                	var r = birthday.val().match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/); 
					if(r==null){
					birthday.error( '出生日期格式错误!' );
					} 
                }
            }//出生日期检测地检测
            if ( ! passport.isMultiValue() ) {
                if ( ! passport.val() ) {
                    passport.error( '护照不能为空!' );
                }
                if ( passport.val().length>=30 ) {
                    passport.error( '护照不是符合的格式!' );
                }
            }//护照检测
            if ( this.inError() ) {
                return false;
            }
        }
    } );  
	$( editorForCreate.field( 'name' ).input() ).on( 'change', function () {
		console.info(editorForCreate.field( 'name' ).input().val());
 		 var res=ConvertPinyin(editorForCreate.field( 'name' ).input().val());
 			editorForCreate.field( 'pinyinName' ).input().val(res);
	} );
	$( editorForEdit.field( 'name' ).input() ).on( 'change', function () {
 		 var res=ConvertPinyin(editorForEdit.field( 'name' ).input().val());
 			editorForEdit.field( 'pinyinName' ).input().val(res);
	} );
});
/* 按钮类------------------------------------------------------------------------------------------------------------------------ */
function btnUpdateState(code) {
       	var show="";
       	if(code==1){
       		show="确定提交所选项目?"
       	}else if(code==0){
       		show="确定取消提交所选项目?"
       	}else if(code==2){
       		show="确定撤销所选项目?"
       	}else if(code==4){
       		show="确定退回并修改所选项目?"
       	}
       	if(confirm(show)){
       	 var visaInfoId =$("#txtVisaInfoId").val(); 
       	 var nowState =$("#state").val(); 
       	 	if(code==1){
       			if(nowState==1||nowState==3){
       				alert("当前的签证状态不允许这次操作!!");
       				return false;
       			}
       		}else if(code==0){
       			if(nowState!=1){
       				alert("当前的签证状态不允许这次操作!!");
       				return false;
       			}
       		}else if(code==2){
       			if(nowState!=3){
       				alert("当前的签证状态不允许这次操作!!");
       				return false;
       			}
       		}else if(code==4){
       			if(nowState!=3){
       				alert("当前的签证状态不允许这次操作!!");
       				return false;
       			}
       		}
       		$.ajax({  
                   type:"POST",  
                   url:"${path}<%=VisaApplicationInfoController.URL_UPDATESTATE%>",  
                   data:{"delitems":visaInfoId,"afterState":code},    
                   success:function(result){ 
                   		var re=JSON.parse(result);
                   		console.info (result);
                   		console.info (result.returnCode);
                   	   if(re.returnCode=="0"){
                       		var url= window.location.search;
                			var arr = url.split('&');
                			console.info(arr);
                			var CustodianID2=new Date().getTime()+''+Math.floor(Math.random() * 8998 + 1000);
                			parent.refresh(arr[arr.length-1]);
                			parent.closeAndActiveTab(arr[arr.length-2],arr[arr.length-1]);
                   	   }else{
                   	   	alert(re.msg);
                   	   }
                   },  
           		   error:function(request) {      // 设置表单提交出错
                	alert(request);  //登录错误提示信息
            	   }
               });  
       	}
       } 
       
function btnUpdateDel () {
               //判断至少写了一项  
               if(confirm("确定删除所选项目?")){  
               var visaInfoId =$("#txtVisaInfoId").val(); 
               var nowState =$("#state").val(); 
               if(nowState!=0){alert("该签证状态不能删除!只有未提交状态才能删除");return false} 
               console.info(visaInfoId+"按钮类id");
               $.ajax({  
                   type:"POST",  
                   url:"${path}<%=VisaApplicationInfoController.URL_DELETE%>",  
                   data:{"delitems":visaInfoId},    
                   success:function(result){ 
                   		var re=JSON.parse(result);
                   		console.info (result);
                   		console.info (result.returnCode);
                   	   if(re.returnCode=="0"){
                       		var url= window.location.search;
                			var arr = url.split('&');
                			console.info(arr);
                			var CustodianID2=new Date().getTime()+''+Math.floor(Math.random() * 8998 + 1000);
                			parent.refresh(arr[arr.length-1]);
                			parent.closeAndActiveTab(arr[arr.length-2],arr[arr.length-1]);
                   	   }else{
                   	   	alert(re.msg);
                   	   }
                   },  
           		   error:function(request) {      // 设置表单提交出错
                	alert(request);  //登录错误提示信息
            	   }
               });  
               }  
       }; 
       
$(function () {
	var getName="";
	$.ajax({
		type: "POST",
		url: "${path}<%=SendAgentController.URL_NAME%>",
		data: {id:"<%=visaInfo.getSendAgentId()%>"},
		async:false,
		success:function(data){
		getName=data;
		}
	});
	var getName2=getName.replace(new RegExp("\"","gm"),"");
	console.info(typeof(getName));
	console.info(getName.replace("\"",""));
	function outputObj(repo) { var description = ""; for (var i in repo) { description += i + " = " + repo[i] + "\n"; } console.info(description); }
	function formatRepo (repo) {
	  outputObj(repo);
      if (repo.loading) {return repo.text;}
      return repo.text+"("+repo.id+")";
    }

    function formatRepoSelection (repo) {
    console.info(repo.text+"qq3243432");
    return repo.text; 
    }
	var sysDict='<%=sysDictJson%>';
	var re = JSON.parse(sysDict);
	getSelect($("#visaType"),'1002',<%=visaInfo.getVisaType()%>,re,0);
	getSelect($("#state"),'1001',<%=visaInfo.getState()%>,re,0);
	getSelect($("#isStateNorthCountry"),'1004',"<%=visaInfo.getIsStateNorthCountry()%>",re,0);
	getSelect($("#pastCameRecord"),'1005',"<%=visaInfo.getPastCameRecord()%>",re,0);
	if($("#visaType").val()=="#"||$("#visaType").val()==0||$("#visaType").val()==1||$("#visaType").val()==2){
			$("#isStateNorthCountry1").hide();
			$("#isPastCome1").hide();
			$("#pastCameRecord1").hide();
	}
	if($("#isPastCome").val()=="#"||$("#isPastCome").val()==0){
	$("#pastCameRecord1").hide();
	}
	$("#visaType").change(function(){
		if($(this).val()=="#"||$(this).val()==0||$(this).val()==1||$(this).val()==2){
			$("#isStateNorthCountry1").hide();
			$("#isPastCome1").hide();
			$("#pastCameRecord1").hide();
		}else if($(this).val()==3){
			$("#isStateNorthCountry1").show();
			$("#isPastCome1").show();
			if($(isPastCome).val()=="1"){
				$("#pastCameRecord1").show();
			}
		}
	})
	$("#isPastCome").change(function(){
		if($(this).val()=="0"||"#"==$("#isPastCome").val()){
			$("#pastCameRecord1").hide();
		}else if($(this).val()=="1"){
			$("#pastCameRecord1").show();
		}
	})
	$("#sendAgentId").select2({
	language: "zh-CN",
	width: "100%",
  	ajax: {
        url: "${path}<%=TravelAgentController.URL_SEARCHSENDAGENT%>",
        dataType: 'json',
        delay: 1000,
        type:"post",
        data: function (params) {
        params.page = params.page || 1;
          return {
            sendAgentCode: params.term, // 关键字
            curPage: params.page, 
            pageSize: 10,
	        singlePage: 0          
          };
        },
        processResults: function (data, params) {
          params.page = params.page || 1;
          return {
            results: data.items,//items:数据 data.total_count:总记录数,items中，字段id为option中的value值，
            pagination: {
              more: (params.page * 10) < data.total_count //页数*每页记录数小于总记录数时，可记录下拉
            }
          };
        },
        cache: true
      },
      escapeMarkup: function (markup) { return markup; },
      minimumInputLength: 0,
      templateResult: formatRepo,
      templateSelection: formatRepoSelection
	});
	var testss=<%=visaInfo.getSendAgentId()%>;
	console.info(testss);
	$("#sendAgentId").append('<option value="<%=visaInfo.getSendAgentId()%>">'+getName2+"</option>");
	$('#incomingDate').datepicker({
	  format: 'yyyy-mm-dd',
      autoclose: true
    });
    $('#leaveDate').datepicker({
	  format: 'yyyy-mm-dd',
      autoclose: true
    });
    $('#addDate').datepicker({
	  format: 'yyyy-mm-dd',
      autoclose: true
    });
	$('#txtVisaInfoId1').hide(); 
    $("#btnUpdate1").click(function () {
    	var state =$("#state").val();
    	if(state !=0&&state!=4){
    		alert("只有修改中和未提交可以进行保存,当前状态无法进行该操作!")
    		return false;
    	}
        var txtVisaInfoId = $("#txtVisaInfoId").val();
        if(txtVisaInfoId == ""){
            alert("请输入签证id");
            return;
        }
        var incomingDate = $("#incomingDate").val();
        if(incomingDate == ""){
            alert("请输入入境日期");
            return;
        }
        var leaveDate = $("#leaveDate").val();
        if(leaveDate == "#"){
            alert("请输入出境日期");
            return;
        }else if(leaveDate<incomingDate){
        	alert("出境日期不能早于入境日期!!");
        	return;
        } 
        var visaType = $("#visaType").val();
        if(visaType == "#"||visaType =="" ){
            alert("请输入签证类型");
            return;
        }
        var sendAgentId = $("#sendAgentId").val();
        if(sendAgentId == ""||sendAgentId==null){
            alert("请输入旅行社");
            return;
        }  
        var entryFlight = $("#entryFlight").val();
        if(entryFlight == "#"||entryFlight =="" ){
            alert("请输入入境航班");
            return;
        }
        var entryPoint = $("#entryPoint").val();
        if(entryPoint == "#"||entryPoint =="" ){
            alert("请输入入境口岸");
            return;
        }
        var exitPoint = $("#exitPoint").val();
        if(exitPoint == "#"||exitPoint =="" ){
            alert("请输入出境口岸");
            return;
        }
        var exitFlight = $("#exitFlight").val();
        if(exitFlight == "#"||exitFlight =="" ){
            alert("请输入出境航班");
            return;
        }
        var isStateNorthCountry2= $("#isStateNorthCountry").val();
        if(visaType=="#"||visaType=="0"||visaType=="1"||visaType=="2"){isStateNorthCountry2="#";}  
        var isPastCome2= $("#isPastCome").val();
        if(visaType=="#"||visaType=="0"||visaType=="1"||visaType=="2"){isPastCome2="#";}  
        var pastCameRecord2= $("#pastCameRecord").val();
        if(isPastCome2=="#"){pastCameRecord2="#"}
        if (visaType=="3"&& isStateNorthCountry2=="#"){
            alert("请选择在哪个县居住!!") ;
            return false;
        }
        $.ajax({
            url:"${path}<%=VisaApplicationInfoController.URL_UPDATE%>",
            type:"post",
            data:{
                id:txtVisaInfoId,
                incomingDate:incomingDate,
				leaveDate:leaveDate,
				visaType:visaType,
				sendAgentId:sendAgentId,
				exitFlight:exitFlight,
				exitPoint:exitPoint,
				entryFlight:entryFlight,
				entryPoint:entryPoint,
				isStateNorthCountry:isStateNorthCountry2,
				isPastCome:isPastCome2,
				pastCameRecord:pastCameRecord2
            },
            success:function(result){
                var re = JSON.parse(result);
                if(re.returnCode=="0"){
                	alert("修改签证信息成功！");
                	var url= window.location.search;
                	var arr = url.split('&');
                	var CustodianID2=new Date().getTime()+''+Math.floor(Math.random() * 8998 + 1000);
                	parent.refresh(arr[arr.length-1]);
                }else{
                    alert(re.msg);
                }
            },
            error:function(request) {      // 设置表单提交出错
                alert(request);  //登录错误提示信息
            }
        });

        return false;
     });
     });
</script>
</body>
</html>
 